from machine import Pin, PWM
import time

led2 = PWM(Pin(2))
led2.freq(1000)  # 设置PWM的频率1Hz-40Mhz

while True:
    for i in range(0, 1024, 2):
        led2.duty(i)  # 设置占空比，越高越亮
        time.sleep_ms(1)

    for i in range(1023, -1, -2):
        led2.duty(i)
        time.sleep_ms(1)


